home *** CD-ROM | disk | FTP | other *** search
- /* ===============
- * PedScrollbar.cc
- * ===============
- */
-
- #include "PedestalDebugging.h"
-
- #include <Fonts.h>
- #include <Windows.h>
-
- #include "PedScrollbar.hh"
-
- #include "Ped1AppProcess.hh"
- #include "PedApplication.hh"
- #include "PedView.hh"
- #include "PedWindow.hh"
-
-
- pascal void ScrollBarActionProc(ControlHandle inControl, short inPart);
-
-
- PedScrollbar::PedScrollbar(PedView &inSuperView, short inOrientation)
- : PedControl(inSuperView), mOrientation(inOrientation), mActionProc(NULL)
- {
- // Would it be significantly more efficient to reuse UPP's?
- mActionProc = NewControlActionProc(ScrollBarActionProc);
- mStepUnit = mJumpUnit = 1;
- }
-
- PedScrollbar::~PedScrollbar()
- {
- }
-
- void
- PedScrollbar::Init()
- {
- }
-
- void
- PedScrollbar::Open()
- {
- Rect bounds;
- unsigned char title[] = "\p";
-
- PedPane::Open();
-
- if (macControl) return;
-
- GetCalcBounds(bounds);
-
- macControl = ::NewControl(mSuperView.Window().Ptr(), &bounds, title,
- false, 0, 0, 0, scrollBarProc, (long)this);
- ::SetControlAction(macControl, mActionProc);
- mJumpUnit = (bounds.bottom - bounds.top) / 2;
- }
-
- void
- PedScrollbar::Close()
- {
- if (macControl) {
- ::DisposeControl(macControl);
- macControl = NULL;
- }
- PedPane::Close();
- }
-
- void
- PedScrollbar::Activate()
- {
- if (macControl) {
- ::ShowControl(macControl);
- }
- }
-
- void
- PedScrollbar::Deactivate()
- {
- if (macControl) {
- ::HideControl(macControl);
- }
- }
-
-
- enum {kPedMsgNone, kPedMsgScroll, kPedMsgNotifyScrolledTo};
-
- void
- PedScrollbar::Scroll(short inDistance, bool inUpdate)
- {
- short v = 0, h = 0;
- if (mOrientation == kPedScrollVertical) {
- v = inDistance;
- } else {
- h = inDistance;
- }
- //mSuperView.Scroll(h, v);
- SPedScrollInfo info = {{v, h}, inUpdate};
- mSuperView.Message(kPedMsgScroll, &info);
- }
-
- void
- PedScrollbar::SetBounds()
- {
- Rect bounds;
-
- GetCalcBounds(bounds);
- SetBounds(bounds);
- }
-
- void
- PedScrollbar::SetBounds(const Rect &inBounds)
- {
- PedPane::SetBounds(inBounds);
- if (macControl) {
- ::HideControl(macControl);
- ::MoveControl(macControl, inBounds.left, inBounds.top);
- ::SizeControl(macControl,
- inBounds.right - inBounds.left,
- inBounds.bottom - inBounds.top );
- ::ShowControl(macControl);
- }
- }
-
-
- void
- PedScrollbar::GetCalcBounds(Rect &outBounds)
- {
- Rect frame;
- Point offset;
-
- mSuperView.GetFrame(frame);
- mSuperView.GetWindowToLocalOffset(offset);
-
- // FIXME: This assumes both scrollbars are present.
- if (mOrientation == kPedScrollVertical) {
- outBounds.top = frame.top + offset.v - 1;
- outBounds.bottom = frame.bottom + offset.v - 14;
- outBounds.left = frame.right + offset.h - 15;
- outBounds.right = frame.right + offset.h + 1;
- } else {
- outBounds.left = frame.left + offset.h - 1;
- outBounds.right = frame.right + offset.h - 14;
- outBounds.top = frame.bottom + offset.v - 15;
- outBounds.bottom = frame.bottom + offset.v + 1;
- }
- }
-
- void
- PedScrollbar::SetStepUnit(short inUnit)
- {
- mStepUnit = inUnit;
- }
-
- void
- PedScrollbar::SetJumpUnit(short inUnit)
- {
- mJumpUnit = inUnit;
- }
-
-
- void
- PedScrollbar::Draw()
- {
- WindowPtr window = mSuperView.Window().Ptr();
- ::UpdateControls(window, window->visRgn);
- }
-
- void
- PedScrollbar::DispatchNullEvent(EventRecord &inEvent)
- {
- }
-
- void
- PedScrollbar::DispatchClickEvent(EventRecord &inEvent)
- {
- if (!macControl) return;
-
- WindowPtr window = mSuperView.Window().Ptr();
- //::SetPort(macWindow);
- Point pt = inEvent.where;
- ::GlobalToLocal(&pt);
- ControlHandle control;
- short part = ::FindControl(pt, window, &control);
- short oldValue, scrollDistance;
- ::ClipRect(&qd.thePort->portRect);
- switch (part) {
- case kControlIndicatorPart:
- oldValue = ::GetControlValue(macControl);
- part = ::TrackControl(macControl, pt, NULL);
- if (part == kControlIndicatorPart) {
- scrollDistance = Value() - oldValue;
- if (scrollDistance != 0) {
- Scroll(scrollDistance);
- }
- }
- break;
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- case kControlPageUpPart:
- case kControlPageDownPart:
- part = ::TrackControl(macControl, pt, (ControlActionUPP)-1);
- break;
- default:
- break;
- }
- }
-
- void
- PedScrollbar::ControlAction(short inPart)
- {
- Rect view;
-
- short scrollDistance;
- switch (inPart) {
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- scrollDistance = mStepUnit;
- break;
- case kControlPageUpPart:
- case kControlPageDownPart:
- scrollDistance = mJumpUnit;
- break;
- default:
- return;
- break;
- }
- if (inPart == kControlUpButtonPart || inPart == kControlPageUpPart) {
- scrollDistance = -scrollDistance;
- }
-
- short oldValue = Value();
- short max = Maximum();
- short value = oldValue + scrollDistance;
- if (value < 0) {
- value = 0;
- } else if (value > max) {
- value = max;
- }
- if (value != oldValue) {
- SetValue(value);
- scrollDistance = value - oldValue;
- Scroll(scrollDistance, kPedScrollRedrawImmediately);
- }
- }
-
- pascal
- void
- ScrollBarActionProc(ControlHandle inControl, short inPart)
- {
- PedScrollbar *scrollbar = (PedScrollbar *)GetControlReference(inControl);
- if (scrollbar == NULL) return;
-
- scrollbar->ControlAction(inPart);
- }
-